/*     */
package cn.cheln.support.v4.pagerui;
/*     */ 
/*     */

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.drawable.Drawable;
import android.graphics.drawable.GradientDrawable;
import android.graphics.drawable.GradientDrawable.Orientation;
import android.util.AttributeSet;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import cn.cheln.support.v4.view.PagerView;

/*     */
/*     */
/*     */
/*     */
/*     */
/*     */
/*     */
/*     */
/*     */
/*     */
/*     */
/*     */
/*     */
/*     */

/*     */
/*     */ public class ViewPagerIndicator extends RelativeLayout
/*     */ implements PagerView.OnPageChangeListener
/*     */ {
    /*     */   private static final int PADDING = 5;
    /*     */ TextView mPrevious;
    /*     */ TextView mCurrent;
    /*     */ TextView mNext;
    /*     */ int mCurItem;
    /*     */ LinearLayout mPreviousGroup;
    /*     */ LinearLayout mNextGroup;
    /*     */ int mArrowPadding;
    /*     */ int mSize;
    /*     */ ImageView mCurrentIndicator;
    /*     */ ImageView mPrevArrow;
    /*     */ ImageView mNextArrow;
    /*     */ int[] mFocusedTextColor;
    /*     */ int[] mUnfocusedTextColor;
    /*     */ OnClickListener mOnClickHandler;
    /*     */ OnPagerSlidingListener pagerTrigger;
    /*     */ PageInfoProvider mPageInfoProvider;
    /*     */   private GradientDrawable mFadingEdgeLeft;
    /*     */   private GradientDrawable mFadingEdgeRight;

    /*     */
/*     */
    public ViewPagerIndicator(Context context, AttributeSet attrs)
/*     */ {
/* 157 */
        super(context, attrs);
/* 158 */
        addContent();
/*     */
    }

    /*     */
/*     */
    public ViewPagerIndicator(Context context, AttributeSet attrs, int defStyle) {
/* 162 */
        super(context, attrs, defStyle);
/* 163 */
        addContent();
/*     */
    }

    /*     */
/*     */
    public ViewPagerIndicator(Context context) {
/* 167 */
        super(context);
/* 168 */
        addContent();
/*     */
    }

    /*     */
/*     */
    public void setOnClickListener(OnClickListener handler)
/*     */ {
/*  65 */
        this.mOnClickHandler = handler;
/*  66 */
        this.mPreviousGroup.setOnClickListener(new OnPreviousClickedListener());
/*  67 */
        this.mCurrent.setOnClickListener(new OnCurrentClickedListener());
/*  68 */
        this.mNextGroup.setOnClickListener(new OnNextClickedListener());
/*     */
    }

    /*     */
/*     */
    public int getCurrentPosition() {
/*  72 */
        return this.mCurItem;
/*     */
    }

    /*     */
/*     */
    public void setPageInfoProvider(PageInfoProvider pageInfoProvider)
/*     */ {
/*  77 */
        this.mPageInfoProvider = pageInfoProvider;
/*     */
    }

    /*     */
/*     */
    public void setFocusedTextColor(int[] col) {
/*  81 */
        System.arraycopy(col, 0, this.mFocusedTextColor, 0, 3);
/*  82 */
        updateColor(0);
/*     */
    }

    /*     */
/*     */
    public void setUnfocusedTextColor(int[] col) {
/*  86 */
        System.arraycopy(col, 0, this.mUnfocusedTextColor, 0, 3);
/*     */
/*  88 */
        this.mNext.setTextColor(-16777216);
/*  89 */
        this.mPrevious.setTextColor(-16777216);
/*     */
/*  92 */
        updateColor(0);
/*     */
    }

    /*     */
/*     */
    public void init(int startPos, int size, PageInfoProvider pageInfoProvider, int dpi, int ifLandscape)
/*     */ {
/*  97 */
        setPageInfoProvider(pageInfoProvider);
/*  98 */
        this.mSize = size;
/*  99 */
        setText(startPos - 1);
/* 100 */
        this.mCurItem = startPos;
/*     */
/* 102 */
        int[] fadingEdgeGradient = {-1184275, 16777215};
/*     */
/* 104 */
        this.mFadingEdgeLeft = new GradientDrawable(Orientation.LEFT_RIGHT, fadingEdgeGradient);
/*     */
/* 106 */
        this.mFadingEdgeRight = new GradientDrawable(Orientation.RIGHT_LEFT, fadingEdgeGradient);
/*     */
/* 109 */
        int width = 0;
/* 110 */
        int deep = 0;
/* 111 */
        int deepheight = 0;
/* 112 */
        if (dpi > 160) {
/* 113 */
            if (ifLandscape > 0) {
/* 114 */
                width = 800;
/* 115 */
                deep = 20;
/* 116 */
                deepheight = 39;
/*     */
            } else {
/* 118 */
                width = 480;
/* 119 */
                deep = 20;
/* 120 */
                deepheight = 39;
/*     */
            }
/*     */
/*     */
        }
/* 125 */
        else if (ifLandscape > 0) {
/* 126 */
            width = 480;
/* 127 */
            deep = 13;
/* 128 */
            deepheight = 25;
/*     */
        } else {
/* 130 */
            width = 320;
/* 131 */
            deep = 13;
/* 132 */
            deepheight = 25;
/*     */
        }
/*     */
/* 138 */
        this.mFadingEdgeLeft.setBounds(0, 0, deep, deepheight);
/* 139 */
        this.mFadingEdgeRight.setBounds(width - deep, 0, width, deepheight);
/*     */
    }

    /*     */
/*     */
    protected void dispatchDraw(Canvas canvas)
/*     */ {
/* 148 */
        super.dispatchDraw(canvas);
/* 149 */
        this.mFadingEdgeLeft.draw(canvas);
/* 150 */
        this.mFadingEdgeRight.draw(canvas);
/*     */
    }

    /*     */
/*     */
    public void setArrows(Drawable prev, Drawable next) {
/* 172 */
        this.mPrevArrow = new ImageView(getContext());
/* 173 */
        this.mPrevArrow.setImageDrawable(prev);
/*     */ 
/* 175 */
        this.mNextArrow = new ImageView(getContext());
/* 176 */
        this.mNextArrow.setImageDrawable(next);
/*     */ 
/* 178 */
        LinearLayout.LayoutParams arrowLayoutParams = new LinearLayout.LayoutParams(-2, -2);
/* 179 */
        arrowLayoutParams.gravity = 17;
/*     */ 
/* 181 */
        this.mPreviousGroup.removeAllViews();
/* 182 */
        this.mPreviousGroup.addView(this.mPrevArrow, arrowLayoutParams);
/* 183 */
        this.mPreviousGroup.addView(this.mPrevious, arrowLayoutParams);
/*     */ 
/* 185 */
        this.mPrevious.setPadding(5, 0, 0, 0);
/* 186 */
        this.mNext.setPadding(0, 0, 5, 0);
/*     */ 
/* 188 */
        this.mArrowPadding = (5 + prev.getIntrinsicWidth());
/*     */ 
/* 190 */
        this.mNextGroup.addView(this.mNextArrow, arrowLayoutParams);
/* 191 */
        updateArrows(this.mCurItem);
/*     */
    }

    /*     */
/*     */
    private void addContent()
/*     */ {
/* 196 */
        this.mFocusedTextColor = new int[]{0, 0, 0};
/* 197 */
        this.mUnfocusedTextColor = new int[]{190, 190, 190};
/*     */ 
/* 200 */
        this.mPrevious = new TextView(getContext());
/* 201 */
        this.mCurrent = new TextView(getContext());
/* 202 */
        this.mNext = new TextView(getContext());
/*     */ 
/* 204 */
        LayoutParams previousParams = new LayoutParams(-2, -2);
/* 205 */
        previousParams.addRule(5);
/*     */ 
/* 207 */
        LayoutParams currentParams = new LayoutParams(-2, -2);
/* 208 */
        currentParams.addRule(14);
/*     */ 
/* 210 */
        LayoutParams nextParams = new LayoutParams(-2, -2);
/* 211 */
        nextParams.addRule(11);
/*     */ 
/* 214 */
        this.mPreviousGroup = new LinearLayout(getContext());
/* 215 */
        this.mPreviousGroup.setOrientation(0);
/* 216 */
        this.mNextGroup = new LinearLayout(getContext());
/* 217 */
        this.mNextGroup.setOrientation(0);
/*     */ 
/* 219 */
        this.mPreviousGroup.addView(this.mPrevious, new LayoutParams(-2, -2));
/* 220 */
        this.mNextGroup.addView(this.mNext, new LayoutParams(-2, -2));
/*     */ 
/* 222 */
        addView(this.mPreviousGroup, previousParams);
/* 223 */
        addView(this.mCurrent, currentParams);
/* 224 */
        addView(this.mNextGroup, nextParams);
/*     */ 
/* 226 */
        this.mPrevious.setSingleLine();
/* 227 */
        this.mCurrent.setSingleLine();
/* 228 */
        this.mNext.setSingleLine();
/*     */ 
/* 230 */
        this.mPrevious.setText("previous");
/* 231 */
        this.mCurrent.setText("current");
/* 232 */
        this.mNext.setText("next");
/*     */ 
/* 234 */
        this.mPrevious.setTextSize(15.0F);
/* 235 */
        this.mCurrent.setTextSize(15.0F);
/* 236 */
        this.mNext.setTextSize(15.0F);
/*     */ 
/* 238 */
        this.mPrevious.setClickable(false);
/* 239 */
        this.mNext.setClickable(false);
/* 240 */
        this.mCurrent.setClickable(true);
/* 241 */
        this.mPreviousGroup.setClickable(true);
/* 242 */
        this.mNextGroup.setClickable(true);
/*     */ 
/* 247 */
        updateColor(0);
/* 248 */
        this.mNext.setTextColor(-7829368);
/* 249 */
        this.mPrevious.setTextColor(-7829368);
/*     */
    }

    /*     */
/*     */
    public void onPageScrollStateChanged(int state)
/*     */ {
/* 254 */
        if (state == 2)
/* 255 */ this.mCurrent.setText("");
/*     */
    }

    /*     */
/*     */
    public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels)
/*     */ {
/* 261 */
        positionOffsetPixels = adjustOffset(positionOffsetPixels);
/*     */ 
/* 263 */
        updatePositions(positionOffsetPixels);
/*     */ 
/* 265 */
        updateColor(positionOffsetPixels);
/* 266 */
        updateArrows(position);
/*     */ 
/* 268 */
        position = updatePosition(position, positionOffsetPixels);
/*     */ 
/* 270 */
        setText(position - 1);
/*     */
    }

    /*     */
/*     */
    public void updatePositions(int positionOffsetPixels)
/*     */ {
/* 276 */
        int textWidth = this.mCurrent.getWidth() - this.mCurrent.getPaddingLeft() - this.mCurrent.getPaddingRight();
/* 277 */
        int maxOffset = getWidth() / 2 - textWidth / 2 - this.mArrowPadding;
/* 278 */
        if (positionOffsetPixels > 0) {
/* 279 */
            maxOffset -= getPaddingLeft();
/* 280 */
            int offset = Math.min(positionOffsetPixels, maxOffset - 1);
/* 281 */
            this.mCurrent.setPadding(0, 0, 2 * offset, 0);
/*     */ 
/* 285 */
            int overlapLeft = this.mPreviousGroup.getRight() - this.mCurrent.getLeft() + this.mArrowPadding;
/* 286 */
            this.mPreviousGroup.setPadding(-Math.max(0, overlapLeft), 0, Math.max(0, overlapLeft), 0);
/* 287 */
            this.mNextGroup.setPadding(0, 0, 0, 0);
/*     */
        }
/*     */
        else {
/* 290 */
            maxOffset -= getPaddingRight();
/* 291 */
            int offset = Math.max(positionOffsetPixels, -maxOffset);
/* 292 */
            this.mCurrent.setPadding(-2 * offset, 0, 0, 0);
/*     */ 
/* 296 */
            int overlapRight = this.mCurrent.getRight() - this.mNextGroup.getLeft() + this.mArrowPadding;
/* 297 */
            this.mNextGroup.setPadding(Math.max(0, overlapRight), 0, -Math.max(0, overlapRight), 0);
/* 298 */
            this.mPreviousGroup.setPadding(0, 0, 0, 0);
/*     */
        }
/*     */
    }

    /*     */
/*     */   void updateArrows(int position)
/*     */ {
/* 304 */
        if (this.mPrevArrow != null) {
/* 305 */
            this.mPrevArrow.setVisibility(position == 0 ? 4 : 0);
/* 306 */
            this.mNextArrow.setVisibility(position == this.mSize - 1 ? 4 : 0);
/*     */
        }
/*     */
    }

    /*     */
/*     */   int updatePosition(int givenPosition, int offset)
/*     */ {
/*     */
        int pos;
/*     */
/* 319 */
        if (offset < 0)
/* 320 */ pos = givenPosition + 1;
/*     */
        else {
/* 322 */
            pos = givenPosition;
/*     */
        }
/* 324 */
        return pos;
/*     */
    }

    /*     */
/*     */   void updateColor(int offset)
/*     */ {
/* 333 */
        offset = Math.abs(offset);
/*     */ 
/* 335 */
        int width = getWidth();
/* 336 */
        float fraction = width == 0 ? 0.0F : offset / (width / 4.0F);
/* 337 */
        fraction = Math.min(1.0F, fraction);
/* 338 */
        int r = (int) (this.mUnfocusedTextColor[0] * fraction + this.mFocusedTextColor[0] * (1.0F - fraction));
/* 339 */
        int g = (int) (this.mUnfocusedTextColor[1] * fraction + this.mFocusedTextColor[1] * (1.0F - fraction));
/* 340 */
        int b = (int) (this.mUnfocusedTextColor[2] * fraction + this.mFocusedTextColor[2] * (1.0F - fraction));
/*     */ 
/* 342 */
        this.mCurrent.setTextColor(-16777216);
/*     */
    }

    /*     */
/*     */   void setText(int prevPos)
/*     */ {
/* 353 */
        if (prevPos < 0)
/* 354 */ this.mPrevious.setText("");
/*     */
        else {
/* 356 */
            this.mPrevious.setText(this.mPageInfoProvider.getTitle(prevPos));
/*     */
        }
/* 358 */
        this.mCurrent.setText(this.mPageInfoProvider.getTitle(prevPos + 1));
/* 359 */
        if (prevPos + 2 == this.mSize)
/* 360 */ this.mNext.setText("");
/*     */
        else
/* 362 */       this.mNext.setText(this.mPageInfoProvider.getTitle(prevPos + 2));
/*     */
    }

    /*     */
/*     */   int adjustOffset(int positionOffsetPixels)
/*     */ {
/* 373 */
        positionOffsetPixels += getWidth() / 2;
/*     */ 
/* 375 */
        positionOffsetPixels %= getWidth();
/*     */ 
/* 377 */
        positionOffsetPixels -= getWidth() / 2;
/* 378 */
        return positionOffsetPixels;
/*     */
    }

    /*     */
/*     */
    public void setOnTriggerListener(OnPagerSlidingListener listener) {
/* 382 */
        this.pagerTrigger = listener;
/*     */
    }

    /*     */
/*     */
    public void onPageSelected(int position)
/*     */ {
/* 388 */
        this.mCurrent.setPadding(0, 0, 0, 0);
/* 389 */
        this.mCurItem = position;
/* 390 */
        if (this.pagerTrigger != null)
/* 391 */ this.pagerTrigger.onChangePagerTrigger(position);
/*     */
    }

    /*     */
/*     */   public static abstract interface OnClickListener
/*     */ {
        /*     */
        public abstract void onNextClicked(View paramView);

        /*     */
/*     */
        public abstract void onPreviousClicked(View paramView);

        /*     */
/*     */
        public abstract void onCurrentClicked(View paramView);
/*     */
    }

    /*     */
/*     */   public static abstract interface PageInfoProvider
/*     */ {
        /*     */
        public abstract String getTitle(int paramInt);
/*     */
    }

    /*     */
/*     */   public static abstract interface OnPagerSlidingListener
/*     */ {
        /*     */
        public abstract void onChangePagerTrigger(int paramInt);
/*     */
    }

    /*     */
/*     */   class OnNextClickedListener
/*     */ implements View.OnClickListener
/*     */ {
        /*     */     OnNextClickedListener()
/*     */ {
/*     */
        }

        /*     */
/*     */
        public void onClick(View v)
/*     */ {
/* 413 */
            if (ViewPagerIndicator.this.mOnClickHandler != null)
/* 414 */ ViewPagerIndicator.this.mOnClickHandler.onNextClicked(ViewPagerIndicator.this);
/*     */
        }
/*     */
    }

    /*     */
/*     */   class OnCurrentClickedListener
/*     */ implements View.OnClickListener
/*     */ {
        /*     */     OnCurrentClickedListener()
/*     */ {
/*     */
        }

        /*     */
/*     */
        public void onClick(View v)
/*     */ {
/* 405 */
            if (ViewPagerIndicator.this.mOnClickHandler != null)
/* 406 */ ViewPagerIndicator.this.mOnClickHandler.onCurrentClicked(ViewPagerIndicator.this);
/*     */
        }
/*     */
    }

    /*     */
/*     */   class OnPreviousClickedListener
/*     */ implements View.OnClickListener
/*     */ {
        /*     */     OnPreviousClickedListener()
/*     */ {
/*     */
        }

        /*     */
/*     */
        public void onClick(View v)
/*     */ {
/* 397 */
            if (ViewPagerIndicator.this.mOnClickHandler != null)
/* 398 */ ViewPagerIndicator.this.mOnClickHandler.onPreviousClicked(ViewPagerIndicator.this);
/*     */
        }
/*     */
    }
/*     */
}

/* Location:           C:\proj\lewa_explorer\libs\lewa.os.jar
 * Qualified Name:     com.lewa.os.ui.ViewPagerIndicator
 * JD-Core Version:    0.6.2
 */